import request from "../utils/request";

export const Login = data => {
    return  request({
        method: 'POST',
        url: '/login',
        data
})
}

// 获取侧边栏数据
export const getMenu = () => {
    return  request({
        method: 'GET',
        url: '/menus'
    })
}
// 获取用户列表
export const getUsers = params => {
    return  request({
        method: 'GET',
        url: '/users',
        params
    })
}

// 修改状态
export const updateState = (uId,type) => {
    return  request({
        method: 'PUT',
        url: `/users/${uId}/state/${type}`,
    })
}

// 添加用户
export const addUserss = data => {
    return request ({
        method: 'POST',
        url: '/users',
        data
    })
}
// 根据id查询用户
export const getUser = (id) => {
    return request ({
        method: 'GET',
        url: `/users/${id}`
    })
}

// 根据id修改用户
export const editUser = (id,params) => {
    return request ({
        method: 'PUT',
        url: `/users/${id}`,
        params
    })
}

// 根据id删除用户
export const deleteUsers = (id) => {
    return request ({
        method: 'DELETE',
        url: `/users/${id}`
    })
}

// 获取权限列表
export const getRights = (type) => {
    return request ({
        method: 'GET',
        url: `/rights/${type}`
    })
}

// 获取角色列表
export const getRoles = () => {
    return request ({
        method: 'GET',
        url: `/roles`
    })
}

// 获取角色列表
export const deleteRoles = (roleId,rightId) => {
    return request ({
        method: 'DELETE',
        url: `/roles/${roleId}/rights/${rightId}`
    })
}

// 角色授权
export const addRolesRights = (roleId,rids) => {
    return request ({
        method: 'POST',
        url: `/roles/${roleId}/rights`,
        data: rids
    })
}
// 分配用户角色
export const putUserRoles = (id,rid) => {
    return request ({
        method: 'PUT',
        url: `/users/${id}/role`,
        data: rid
    })
}

// 获取所有分类
export const getCategories = (params) => {
    return request ({
        method: 'GET',
        url: `/categories`,
        params
    })
}

// 添加分类
export const addCategories = (data) => {
    return request ({
        method: 'POST',
        url: `/categories`,
        data
    })
}

